home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000093_icon-group-sender _Fri Oct 24 08:39:27 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by cheltenham.cs.arizona.edu (8.8.7/8.8.7) with SMTP id IAA26548
  4.     for <icon-group-addresses@cheltenham.CS.Arizona.EDU>; Fri, 24 Oct 1997 08:39:26 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA24457; Fri, 24 Oct 1997 08:39:25 -0700
  7. To: icon-group@cs.arizona.edu
  8. Date: 24 Oct 1997 03:16:42 GMT
  9. From: espie@litp.ibp.fr (Marc ESPIE)
  10. Message-Id: <62p3uq$sup$1@vishnu.jussieu.fr>
  11. Organization: LIAFA, Paris
  12. Sender: icon-group-request@cs.arizona.edu
  13. References: <Stuart.Robinson-2410970146220001@asianstmg-229.anu.edu.au>, <Stuart.Robinson-2410971258070001@asianstmg-229.anu.edu.au>
  14. Reply-To: espie@litp.ibp.fr
  15. Subject: Re: tabulating values
  16. Errors-To: icon-group-errors@cs.arizona.edu
  17. Status: RO
  18.  
  19. In article <Stuart.Robinson-2410971258070001@asianstmg-229.anu.edu.au>,
  20. Stuart Robinson <Stuart.Robinson@anu.edu.au> wrote:
  21. >Well, I've now received six responses to my query, none of which provide a
  22. >solution to the problem.  I really do appreciate the responses, but four
  23. >of the responses consisted of people essentially saying "Heck, that's
  24. >trivial" without proving it by actually providing a working solution and
  25. >the two responses that did actually contain code failed to provide a
  26. >solution.  Here they are:
  27.  
  28. This problem is trivial... I'm sorry for you, I wish that people would
  29. at least check what they're writing before answering.
  30.  
  31. >PROGRAM #1
  32. >----------
  33. >procedure main()
  34. >
  35. >t := table(0)
  36. >while t[!read()] +:= 1
  37.  
  38. this is the erroneous line.
  39. while t[read()] +:= 1
  40. would be mostly correct.
  41. The !read() does what it should on a string, namely take every character
  42. one at a time.
  43. However, this won't truely work for numerical values, as it distinguishes
  44. 010 
  45. from
  46. 10...
  47. Try:
  48. while t[integer(read())] +:= 1
  49. which will convert explicitly the line read to integer.
  50. Second catch: this one will fail as soon as you encounter a line that does
  51. not hold an integer number. I would write
  52. while n := read() do
  53.     t[integer(n)] +:= 1
  54.  
  55. that way, I can add an error condition whenever integer() fails, and
  56. separate it from the stop condition of the main loop.
  57.  
  58. >write("value    n")
  59. >every i := !sort(t) do write(left(i[1], 9), left(i[2], 4))
  60.  
  61. >end
  62.  
  63.  
  64. >PROGRAM #2
  65. >----------
  66. >procedure main()
  67. >
  68. >count := table(0)
  69. >every n := read() do 
  70. >count[n] +:= 1
  71. >
  72. >write("value\tn")
  73. >every n := key(count) do
  74. >write(n, "\t", count[n])
  75.  
  76. This one should check what key() actually returns... which is a list.
  77. It does suffer from the same `string is not an integer as program #1'.
  78.  
  79. Come on guys, when somebody asks a rather simple question, giving him
  80. an half-baked program that doesn't work won't probably give him a clue
  81. about what's wrong.
  82.  
  83. Stuart: I'm curious about the way you're using Icon. If you're truely 
  84. stuck with the program library as far as programming goes, you're only
  85. using a small part of Icon. How about trying to learn and program ?
  86. -- 
  87.     Marc Espie (espie@litp.ibp.fr)
  88.